package com.tidc.seaserverweb.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.tidc.seaservermodel.entity.Commitment;
import com.tidc.seaservermodel.entity.Fres;
import com.tidc.seaservermodel.exception.TidcBadParent;
import com.tidc.seaserverservice.service.SupervisorCommitmentService;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;


@RestController
@RequestMapping("/supervisor/commitment")
public class SupervisorCommitmentController {
    @Resource
    private SupervisorCommitmentService supervisorCommitmentService;
    /**
     * 获取父级账号的承诺列表 type关系到是已完成还是未完成0是未完成
     * @param type
     * @param pageSize
     * @param pageNum
     * @param authentication
     * @return
     * @throws TidcBadParent
     */
    @GetMapping("/list")
    public Fres<Map<Object,Object>> getCommitmentList(@RequestParam("type") int type,@RequestParam("pageSize") int pageSize, @RequestParam("pageNum") int pageNum, Authentication authentication) throws TidcBadParent {
        return supervisorCommitmentService.getCommitmentList(type,pageSize,pageNum,authentication);
    }
    @PutMapping("/fulfill")
    public Fres<String> fulfillCommitment(@RequestBody Commitment commitment,Authentication authentication) throws JsonProcessingException {
        return supervisorCommitmentService.fulfillCommitment(commitment,authentication);
    }
}
